/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.tree;

import java.awt.*;

import jdbcmanager.swing.*;
import jdbcmanager.app.*;
import jdbcmanager.dbtools.datatypes.*;

/**
 * Tree nodes representing a UDT DB entity.
 * @author Francisco Morero Peyrona
 */
final class NodeUDT extends JdbcTreeNode
{
   private JFrameMain.JDBCManagerInternalFrame frame = null;
 
   NodeUDT( String sCatalog, String sSchema )
   {
      super( icon_tree_udt, new DbEntityDescriptor( sCatalog, sSchema, "User Types" ) );
      
      // Trick to force the tree to show the RootHandles (it will be removed before adding real nodes)
      add( new NodeCatalog( "" ) );
      setInvalidActions();
   }

   NodeUDT( DbEntityDescriptor ded, boolean bUDT )
   {
      super( icon_tree_udt, ded );

      setAllowsChildren( ! bUDT );
      setInvalidActions();
   }
   
   boolean isInitialised()
   {
      return this.bWasInit || ! getAllowsChildren();
   }

// NEXT: implementar: new(), edit(), rename() y delete()
   boolean new_()
   {
      App.showMessage( "Option under development.\n"+
                       "For security reasons this option\n"+
                       "will not available until next version." );

      return false;
   }

   void open()
   {
      if( this.frame == null || this.frame.isClosed() )
      {
         App.setCursor( Cursor.WAIT_CURSOR );
         this.frame = App.getFrameMain().openUDT( ded );
         App.restoreCursor();
      }
      else
      {
         this.frame.setSelected( true );
         this.frame.restore();
      }
   }

   boolean edit()
   {
      App.showMessage( "Option under development.\n"+
                       "For security reasons this option\n"+
                       "will not available until next version." );

      return false;
   }
   
   boolean rename( String sNewName )
   {
      App.showMessage( "Rename", "Option under development.\n"+
                       "For security reasons this option\n"+
                       "will not available until next version." );                       
      /*
      if( this.frame != null )
         this.frame.rename( sNewName );
      */                       
       return false;  
   }

   boolean delete()
   {
      App.showMessage( "Option under development.\n"+
                        "For security reasons this option\n"+
                        "will not available until next version." );                 
      /*
      if( this.frame != null )
         this.frame.dispose();
      */

      return false;
   }

   void info()
   {
      // Nothing to do
   }
   
   private void setInvalidActions()
   {
      if( getAllowsChildren() )
      {
         setOpenable(   false );
         setEditable(   false );
         setDeleteable( false );
      }
      else
      {
         setRefreshable( false );
      }
      
      setInfoable( false );
   }
}